﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Xml;

namespace WeiSha.Core
{
	// Token: 0x0200000C RID: 12
	public class Copyright
	{
		// Token: 0x17000014 RID: 20
		// (get) Token: 0x0600004D RID: 77 RVA: 0x00003AEC File Offset: 0x00001CEC
		public static string File
		{
			get
			{
				bool flag = string.IsNullOrWhiteSpace(Copyright._file);
				if (flag)
				{
					Copyright._file = Server.MapPath("~/copyright.weisha");
					bool flag2 = !global::System.IO.File.Exists(Copyright._file);
					if (flag2)
					{
						return null;
					}
				}
				return Copyright._file;
			}
		}

		// Token: 0x17000015 RID: 21
		// (get) Token: 0x0600004E RID: 78 RVA: 0x00003B38 File Offset: 0x00001D38
		public static Dictionary<string, string> Items
		{
			get
			{
				return Copyright.GetCopyright();
			}
		}

		// Token: 0x0600004F RID: 79 RVA: 0x00003B50 File Offset: 0x00001D50
		public static string Value(string key)
		{
			Dictionary<string, string> items = Copyright.Items;
			string text = string.Empty;
			foreach (KeyValuePair<string, string> keyValuePair in items)
			{
				bool flag = keyValuePair.Key.Equals(key, StringComparison.OrdinalIgnoreCase);
				if (flag)
				{
					text = keyValuePair.Value;
					break;
				}
			}
			return text;
		}

		// Token: 0x06000050 RID: 80 RVA: 0x00003BD0 File Offset: 0x00001DD0
		private static Dictionary<string, string> GetCopyright()
		{
			Cache cache = HttpRuntime.Cache;
			Dictionary<string, string> dictionary = cache.Get(Copyright._cachename) as Dictionary<string, string>;
			bool flag = dictionary == null;
			if (flag)
			{
				bool flag2 = Copyright.File != null && global::System.IO.File.Exists(Copyright.File);
				if (flag2)
				{
					XmlDocument xmlDocument = new XmlDocument();
					xmlDocument.Load(Copyright.File);
					XmlNode lastChild = xmlDocument.LastChild;
					bool flag3 = lastChild != null;
					if (flag3)
					{
						dictionary = new Dictionary<string, string>();
						XmlNodeList childNodes = lastChild.ChildNodes;
						foreach (object obj in childNodes)
						{
							XmlNode xmlNode = (XmlNode)obj;
							bool flag4 = xmlNode.NodeType != XmlNodeType.Element;
							if (!flag4)
							{
								dictionary.Add(xmlNode.Name, xmlNode.InnerText);
							}
						}
					}
					cache.Insert(Copyright._cachename, dictionary, new CacheDependency(Copyright.File));
				}
				else
				{
					dictionary = new Dictionary<string, string>();
				}
			}
			return dictionary;
		}

		// Token: 0x06000051 RID: 81 RVA: 0x00003CF8 File Offset: 0x00001EF8
		public string ToJson()
		{
			Dictionary<string, string> copyright = Copyright.GetCopyright();
			string text = "{";
			foreach (KeyValuePair<string, string> keyValuePair in copyright)
			{
				text = string.Concat(new string[]
				{
					text,
					"'",
					keyValuePair.Key,
					"':'",
					HttpContext.Current.Server.UrlEncode(keyValuePair.Value),
					"',"
				});
			}
			bool flag = text.EndsWith(",");
			if (flag)
			{
				text = text.Substring(0, text.Length - 1);
			}
			text += "}";
			return text;
		}

		// Token: 0x04000016 RID: 22
		private static string _cachename = "WEISHAKEJI_COPYRIGHT";

		// Token: 0x04000017 RID: 23
		private static string _file = "";
	}
}
